<?php defined('IN_KG') or exit('Access Invalid!');?>
<style>
	#images img{
		width: 300px;
		margin-right: 10px;
		display: inline-block;
	}
	p{
		margin-bottom: 10px;
	}
</style>
<script src="<?php echo RESOURCE_SITE_URL;?>/js/jquery.ajaxContent.pack.js"></script>
<script src="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/i18n/zh-CN.js"></script>
<script src="<?php echo RESOURCE_SITE_URL;?>/js/common_select.js"></script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/fileupload/jquery.iframe-transport.js" charset="utf-8"></script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/fileupload/jquery.ui.widget.js" charset="utf-8"></script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/fileupload/jquery.fileupload.js" charset="utf-8"></script>

<div id="evaluates">
    <label for="goods_id">请填写商品id：</label>
    <input type="text" id="goods_id" name="goods_id" placeholder="商品id" class="text w150">
    <br>
    <p>评分： 
    <select name="" id="score">
    <option value="5">5</option>
        <option value="4">4</option>
        <option value="3">3</option>
        <option value="2">2</option>
        <option value="1">1</option>    
    </select>分</p>
    <p>时间：<input type="date" id="dateline" ></p>
    <p>评论内容：</p>
    <p><textarea name="comment" id="comment" cols="30" rows="10"></textarea></p>

    <p>
        上传图片：
        <input type="file" id="file" name="file_0">
    </p>
    <button id="submit" class="ncbtn ncbtn-mint mt10">提交</button>
    <div id="images"></div>
</div>
<script>
	var images = $("#images"),
        evaluates = $("#evaluates"),
		comment_image = [];
	$('#file').fileupload({
        dataType: 'json',
        url: SITEURL + '/index.php?control=batch&op=file_upload',
        // url: '/mobile/sns_album?op=file_upload',
        formData: {key:'d8cfd02184881d5102408acac6538ad4'},
        add: function (e,data) {
        	// $('img[nctype="goods_image"]').attr('src', SHOP_TEMPLATES_URL + '/images/loading.gif');
        	// console.log(e, data);
            data.submit();
        },
        done: function (e,data) {
        	data = data.result;
        	comment_image.push(data.file_name);
        	$('<img>').attr('src', data.file_url).appendTo(images);
        	// console.log(e, data)
            /*var param = data.result;
            if (typeof(param.error) != 'undefined') {
                alert(param.error);
                $('img[nctype="goods_image"]').attr('src',DEFAULT_GOODS_IMAGE);
            } else {
                $('input[nctype="goods_image"]').val(param[0].name);
                $('img[nctype="goods_image"]').attr('src',param[0].thumb_name);
            }*/
        }
    });
    $("#submit").click(function(event) {
    	var formdata = {
    		goods_id: $("#goods_id").val(),
    		comment: $("#comment").val(),
    		score: $("#score").val(),
    		geval_image: comment_image.join(','),
            dateline: $("#dateline").val(),
    	}
    	$.post(SITEURL + '/index.php?control=batch&op=save', formdata, function(data, textStatus, xhr) {
    		if (typeof data == 'string') {
    			data = JSON.parse(data);
    		}
    		console.log(data);
    		var msg = [];
            msg.push(data.evaluation ? '添加评论成功' : '添加评论失败');
            msg.push(data.order ? '添加销量成功' : '添加销量失败');
            alert(msg.join('，'));
            // 重置
            comment_image = [];
            images.html(' ');

            var newdiv = $('<div>');
            newdiv.append($('<p>').html(data.evaluate.geval_frommembername+', '+data.evaluate.geval_addtime))
                    .append($('<p>').html(data.evaluate.geval_goodsname))
                    .append($('<p>').html(data.evaluate.geval_content))
                    .appendTo(evaluates)
        });
    });
</script>